package service;

import dao.ProductDao;
import model.Product;


import java.sql.SQLException;
import java.util.List;

public class ProductService {
    private ProductDao pDao=new ProductDao();
    public List<Product> selectGoodsByCategoryID(int typeID)
    {
        List<Product> list=null;
        try {
            list=pDao.selectGoodsByCategoryID(typeID);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public float getPriceById(int id) {
        float price = 0;
        try{
            price=pDao.getPriceById(id);
        }catch(SQLException e){
            e.printStackTrace();
        }
        return price;
    }
    public int getReceiverIdById(int id){
        int userId=0;
        try{
            userId=pDao.getReceiverIdById(id);
        }catch (SQLException e){
            e.printStackTrace();
        }
        return userId;
    }
    public List<Product> selectProductByStatus(boolean status) throws SQLException {
        return pDao.selectProductByStatus(status);
    }
    public List<Product> GetAllOnSaleProduct()
    {
        List<Product> list=null;
        try {
            list=pDao.GetAllOnSaleProduct();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public List<Product> GetProductsByUserId(int userId)
    {
        List<Product> list=null;
        try {
            list=pDao.GetProductByReceiverId(userId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public List<Product> GetProductByReceiverIdAndStatus(int userId,boolean status)
    {
        List<Product> list=null;
        try {
            list=pDao.GetProductByReceiverIdAndStatus(userId,status);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public List<Product> GetNotOnSaleProductByReceiverId(int userId,boolean is_removed)
    {
        List<Product> list=null;
        try {
            list=pDao.GetNotOnSaleProductByReceiverId(userId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public Product getGoodsById(int id) {
        Product p=null;
        try {
            p = pDao.getGoodsById(id);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return p;
    }
    public void insert(Product goods) {
        try {
            pDao.insert(goods);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public void update(Product goods) {
        try {
            pDao.update(goods);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public void delete(int id) {
        try {
            pDao.delete(id);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
